<%= render :partial => 'spree/admin/shared/product_tabs', :locals => {:current => 'Images'} %>

<% admin_breadcrumb(plural_resource_name(Spree::Image)) %>


<% content_for :page_actions do %>
  <% if can?(:create, Spree::Image) %>
    <li><%= link_to_with_icon('plus', Spree.t(:new_image), new_admin_product_image_url(@product), :id => 'new_image_link', :class => 'button') %></li>
  <% end %>
<% end %>

<div id="images" data-hook></div>

<% unless @product.images.any? || @product.variant_images.any? %>
  <div class="no-objects-found">
    <%= Spree.t(:no_images_found) %>.
  </div>
<% else %>
  <table class="index sortable" data-hook="images_table" data-sortable-link="<%= update_positions_admin_product_images_url(@product) %>">
    <colgroup>
      <col style="width: 5%">
      <col style="width: 10%">
      <% if @product.has_variants? %>
        <col style="width: 25%">
      <% end %>
      <col style="width: 45%">
      <col style="width: 15%">
    </colgroup>
    <thead>
      <tr data-hook="images_header">
        <th colspan="2"><%= Spree.t(:thumbnail) %></th>
        <% if @product.has_variants? %>
          <th><%= Spree::Variant.model_name.human %></th>
        <% end %>
        <th><%= Spree::Image.human_attribute_name(:alt) %></th>
        <th class="actions"></th>
      </tr>
    </thead>

    <tbody>
      <% (@product.variant_images).each do |image| %>
        <tr id="<%= spree_dom_id image %>" data-hook="images_row" class="<%= cycle('odd', 'even')%>">
          <td class="no-border">
            <% if can?(:update_positions, Spree::Image) %>
              <span class="handle"></span>
            <% end %>
          </td>
          <td>
            <%= link_to image_tag(image.attachment.url(:mini)), image.attachment.url(:product) %>
          </td>
          <% if @product.has_variants? %>
            <td><%= options_text_for(image) %></td>
          <% end %>
          <td><%= image.alt %></td>
          <td class="actions">
            <% if can?(:update, image) %>
              <%= link_to_with_icon 'edit', Spree.t('actions.edit'), edit_admin_product_image_url(@product, image), :no_text => true, :data => {:action => 'edit'} %>
            <% end %>
            <% if can?(:destroy, image) %>
              <%= link_to_delete image, { :url => admin_product_image_url(@product, image), :no_text => true } %>
            <% end %>
          </td>
        </tr>
      <% end %>
    </tbody>
  </table>
<% end %>
